package com.dream.keigezhushou.Activity.acty.personal;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.activity.BaseActivity;
import com.dream.keigezhushou.Activity.acty.listen.HotRecommendActivity;
import com.dream.keigezhushou.Activity.adapter.MyRingAdapter;
import com.dream.keigezhushou.Activity.pop.MoreWindow;
import com.dream.keigezhushou.Activity.pop.MoreWindowToMusicMessage;
import com.dream.keigezhushou.Activity.pop.PoupWindow;
import com.dream.keigezhushou.Activity.pop.SharePoupWindow;
import com.dream.keigezhushou.Activity.wigdt.DividerItemDeoration;
import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MyRingActivity extends BaseActivity {

    @BindView(R.id.iv_return)
    ImageView ivReturn;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.lv_ring)
    RecyclerView lvRing;
    private MyRingAdapter adapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_ring);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    //初始化界面
    protected void initView() {

        tvTitle.setText("铃声");
    }

    //初始化数据
    protected void initData() {

        ivReturn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                //返回
                finish();
            }
        });

        //创建适配器
        adapter = new MyRingAdapter(this);
        lvRing.setLayoutManager(new LinearLayoutManager(this));
        lvRing.addItemDecoration(new DividerItemDeoration(this,DividerItemDeoration.VERTICAL_LIST));
        lvRing.setAdapter(adapter);

        adapter.setOnItemClickListener(new MyItemClickListener() {
            @Override
            public void onItemClick(int position) {

            }

            @Override
            public void onBtnClick(int position) {

                final PoupWindow moreWindow = new PoupWindow(View.inflate(MyRingActivity.this, R.layout.layout_ring_diglog1, null), MyRingActivity.this, RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
                moreWindow.showPopAtLocation(lvRing, Gravity.BOTTOM);
                moreWindow.setItemListener(new PoupWindow.ItemClickListener() {
                    @Override
                    public void onClick() {

                    }

                    @Override
                    public void onSingDetail() {


                        WindowManager wm = (WindowManager) MyRingActivity.this
                                .getSystemService(Context.WINDOW_SERVICE);

                        int width = wm.getDefaultDisplay().getWidth();
                        int height = wm.getDefaultDisplay().getHeight();


                        SharePoupWindow sharePoupWindow = new SharePoupWindow(View.inflate(MyRingActivity.this, R.layout.layout_ring_diglog2, null), MyRingActivity.this, width, ViewGroup.LayoutParams.WRAP_CONTENT);
//                       moreWindow.setBackColorState(0);
                        sharePoupWindow.showPopAtLocation(lvRing, Gravity.BOTTOM);
                        sharePoupWindow.setItemListener(new SharePoupWindow.ItemClickListener(){

                            @Override
                            public void onClick() {

                            }
                        });
                        moreWindow.backGroundAlpha(0.4f);


                    }
                });

            }
        });
    }



    public interface MyItemClickListener {
        public void onItemClick(int position);

        public void onBtnClick(int position);
    }


}
